package cn.study.interceptor;

import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class UserLogininterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        String uri = request.getRequestURI();
        if (      uri.endsWith("js")
                ||uri.endsWith("css")
                ||uri.endsWith("jpg")
                ||uri.endsWith("png")
                ||uri.endsWith("eoc")
                ||uri.endsWith("svg")
                ||uri.endsWith("ttf")
                ||uri.endsWith("woff")
                ||uri.endsWith("woff2")
        ){
            return true ;
        }
        if(request.getSession().getAttribute("USER")==null){
            request.setAttribute("msg","没有权限请先登录");
            request.getRequestDispatcher("/").forward(request,response);
            return false;
        }else {
            return true;
        }

    }
}
